﻿using AutoMapper;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VM.Common.Result;
using VM.Entity.EntityDto.System.Code;
using VM.Entity.EntityMap.System.Code;
using VM.IBLL.System.Code;
using VM.IDAL;
using VM.IDAL.System.Code;
namespace VM.BLL.System.Code
{
    public class CodeHelperBLL : BaseBLL, ICodeHelperBLL
    {
 
        private readonly ICodeHelperDAL _ICodeHelperDAL;
        private readonly IMapper _IMapper;

        public CodeHelperBLL( ICodeHelperDAL iCodeHelperDAL, IMapper iMapper)
        {
            _ICodeHelperDAL=iCodeHelperDAL;
            _IMapper=iMapper;
        }



        public string getCodeInfoByMenuId(int menuId)
        {

            throw new NotImplementedException();
        }

        /// <summary>
        /// 添加编码规则
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public ApiResult insertCodeRule(addCodeRuleDto obj)
        {
            sys_codeRule objRes = _IMapper.Map<addCodeRuleDto, sys_codeRule>(obj);
            ApiResult res = new ApiResult();
            int Res = _ICodeHelperDAL.addCodeRule(objRes);
            if (Res > 0)
            {
                res.code = 200;
                res.msg = $@"成功插入{Res}条数据";

            }
            else
            {
                res.code = 403;
                res.msg = $@"成功失败";

            }
            return res;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="UserId"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ApiDataResult<PagingData<getCodeRuleListDto>> getCodeRuleList(string Name, int UserId, int pageSize, int pageIndex)
        {
            PagingData<getCodeRuleListDto> dataRes=   _ICodeHelperDAL.getCodeRuleListDto(Name,UserId,pageSize,pageIndex);
            ApiDataResult<PagingData<getCodeRuleListDto>> res = new ApiDataResult<PagingData<getCodeRuleListDto>>()
            {
                code = 200,
                msg = "查询成功",
                data = dataRes
            };
            return res;
             
        }


        public ApiResult updateCodeRule(updateCodeRuleDto obj)
        {
            sys_codeRule objSend = _IMapper.Map<updateCodeRuleDto, sys_codeRule>(obj);
            ApiResult res = new ApiResult();
            int Res = _ICodeHelperDAL.updateCodeRule(objSend);
            if (Res > 0)
            {
                res.code = 200;
                res.msg = $@"成功更新{Res}条数据";

            }
            else
            {
                res.code = 403;
                res.msg = $@"更新失败";

            }
            return res;
        }
    }
}
